-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement getting terminal size for windows and linux. #77
base: master
Are you sure you want to change the base?
Conversation
Also use impl Trait
I can't get it to work for TerminfoTerm (mintty) in windows - it reports incorrect information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I have a few minor changes I'd like to see but this looks good otherwise.
/// A struct representing the number of columns and rows of the terminal, and, if available, the | ||
/// width and height of the terminal in pixels | ||
#[derive(Debug, PartialEq, Hash, Eq, Copy, Clone, Default)] | ||
pub struct Dims { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind just calling this Dimensions (or Size)?
@@ -390,6 +407,9 @@ pub trait Terminal: Write { | |||
/// Returns `Ok(true)` if the deletion code was printed, or `Err(e)` if there was an error. | |||
fn carriage_return(&mut self) -> Result<()>; | |||
|
|||
/// Gets the size of the terminal window, if available | |||
fn dims(&self) -> Result<Dims>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I'd call this either dimensions
or size
. dim
means something else so dims
is a bit confusing.
} | ||
} | ||
|
||
impl From<libc::winsize> for Dims { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to implement this? I can't see users actually needing to call this outside of term. I'd just do this conversion directly (i.e., implement a function or inline the conversion) instead of implementing From
.
@@ -283,6 +289,87 @@ pub struct TerminfoTerminal<T> { | |||
ti: TermInfo, | |||
} | |||
|
|||
#[cfg(unix)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't actually have to duplicate this entire implementation; you can just cfg
out the specific function.
@@ -0,0 +1,13 @@ | |||
// An example of the avaiable functionality in term |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely accurate... (to me, this implies that this is all available functionality).
Note to self: make sure to look at issue 63 |
I can't get it to work for TerminfoTerm on windows (using the windows code reports the wrong values) so it is marked not supported.